package pt.iscte.dcti.pa.view;

import java.util.Observable;
import java.util.Observer;

public class VisibleElement extends Observable implements Observer {

	private int xx;
	private int yy;
	private String value;
	private WorksheetView view;
	
	public VisibleElement (int _xx, int _yy) {
		super();
		this.xx = _xx;
		this.yy = _yy;
		this.value = null;
	}
	
	public VisibleElement(int _xx, int _yy, WorksheetView _view) {
		super();
		this.xx = _xx;
		this.yy = _yy;
		this.view = _view;
		this.value = null;
	}
	
	public VisibleElement (int _xx, int _yy, String _value) {
		super();
		this.xx = _xx;
		this.yy = _yy;
		this.value = _value;
		this.view = null;
	}
	
	public int getXX() {
		return this.xx;
	}
	
	public int getYY() {
		return this.yy;
	}
	
	public String getValue() {
		return this.value;
	}
	
	public void setValue(String _value) {
		this.value = _value;
		
		setChanged();
		notifyObservers();
	}
	/*
	public void fireObserver() {
		
		notifyObservers(new int[] {this.xx, this.yy });
	}
*/
	@Override
	public void update(Observable o, Object arg) {		
		//Actualizado pelo Model (pt.iscte.dcti.pa.model.Cell)
		String newValue = (String)arg;
		System.out.println(String.format("[View] Model is updating cell value: XX: %s; YY: %s; NewValue: %s", this.xx, this.yy, newValue));
		this.view.setCellText(this.xx, this.yy, newValue);		
	}
}
